using System;
using System.Windows;
using System.Windows.Media;
namespace Microsoft.Phone.Controls.Maps.Core
{
	public static class MatrixHelper
	{
		public static void Rotate(ref Matrix matrix, double angle)
		{
			Matrix matrix2 = MatrixHelper.CreateRotationMatrix(angle, 0.0, 0.0);
			matrix = MatrixHelper.Multiply(ref matrix, ref matrix2);
		}
		public static void RotateAt(ref Matrix matrix, double angle, Point center)
		{
			Matrix matrix2 = MatrixHelper.CreateRotationMatrix(angle, center.get_X(), center.get_Y());
			matrix = MatrixHelper.Multiply(ref matrix, ref matrix2);
		}
		public static void Translate(ref Matrix matrix, double translateX, double translateY)
		{
			matrix.set_OffsetX(matrix.get_OffsetX() + translateX);
			matrix.set_OffsetY(matrix.get_OffsetY() + translateY);
		}
		private static Matrix Multiply(ref Matrix matrix1, ref Matrix matrix2)
		{
			return new Matrix(matrix1.get_M11() * matrix2.get_M11() + matrix1.get_M12() * matrix2.get_M21(), matrix1.get_M11() * matrix2.get_M12() + matrix1.get_M12() * matrix2.get_M22(), matrix1.get_M21() * matrix2.get_M11() + matrix1.get_M22() * matrix2.get_M21(), matrix1.get_M21() * matrix2.get_M12() + matrix1.get_M22() * matrix2.get_M22(), matrix1.get_OffsetX() * matrix2.get_M11() + matrix1.get_OffsetY() * matrix2.get_M21() + matrix2.get_OffsetX(), matrix1.get_OffsetX() * matrix2.get_M12() + matrix1.get_OffsetY() * matrix2.get_M22() + matrix2.get_OffsetY());
		}
		private static Matrix CreateRotationMatrix(double degrees, double centerX, double centerY)
		{
			double num = degrees * 3.1415926535897931 / 180.0;
			double num2 = Math.Sin(num);
			double num3 = Math.Cos(num);
			double num4 = centerX * (1.0 - num3) + centerY * num2;
			double num5 = centerY * (1.0 - num3) - centerX * num2;
			Matrix result = new Matrix(num3, num2, -num2, num3, num4, num5);
			return result;
		}
	}
}
